/**
 * @description  质押券信息
 * @author wangjianjun
 */
import React, { PureComponent } from 'react';
import { PrimaryC, TableC, NoDataMaskC, codeType, SecuritiesCodeC, InputNumberC } from '../../../../comps';
import uuid from 'es6-uuid';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Select } from 'antd';
import { depCopy } from '../../../../utils/utils';
import moment from 'moment';
import _ from 'lodash';
import { message } from 'antd';
import style from './index.less';
import { connect } from 'dva';
import 'moment/locale/zh-cn';
const FormItem = Form.Item;
@Form.create()
@connect(({ exchangeAgreement }) => ({ exchangeAgreement }))
export default class PledgeBondsInfor extends PureComponent {
  constructor(props) {
    super(props);
    this.cloneDataSource = null;
    this.state = {
      title: '新增',
      visible: false,
      creator: null,
      pledgeBondCode: null,
      pledgeAmount: null,
      conversionRate: null,
      transactionAmount: null,
      totalFaceValue: null,
      repurchaseInterest: null,
      expireAmount: null,
      pledgeBondName: null,
      canUse: null,
      dueDate: null,
      addDisable: true,
      oldPledgeBondCodeDisable: false,
      changePledgeBondCode: false, // 如果是逆回购，需要换债券代码
      dataSource: [],
      id: null,
      hqId: [], //用来保持换券的id
      disabled: false,
      hide: false,
      secucode: null,
      sybj: null,
      securitiesCodeValue: null,
      reTransactionAmount: null, //用来记录成交金额(元)
      pledgeAmountDisabled: false,
      isAdd: false,
      editDataSource: [], //保存编辑前数据
      onRef: () => {}, // 本组件的引用
      oldPledgeBondCode: undefined,
      oldPledgeBondName: undefined,
      oldTransactionAmount: undefined,
    };
  }

  componentDidMount() {
    // 父组件对本组件的引用
    this.props.edit !== false ? this.props.onRef(this) : null; // 详情页面无需指令操作
  }

  UNSAFE_componentWillReceiveProps(nextProps) {
    if (nextProps.initValue) {
      this.setState({
        dataSource: nextProps.initValue,
      });
    }
    if (nextProps.edit == false) {
      this.setState({
        hide: true,
      });
    }

    if (nextProps.tradeBook == '1') {
      this.setState({
        hide: false,
      });
    }

    if (nextProps.quotationType && (nextProps.quotationType == '4' || nextProps.quotationType == '9')) {
      if (this.cloneDataSource == null) {
        if (this.dataSource1) {
          this.cloneDataSource = depCopy(this.dataSource1);
        }
      }
    }

    if (nextProps.quotationType && nextProps.quotationType != '4' && nextProps.quotationType != '9' && nextProps.quotationType != this.props.quotationType) {
      if (this.cloneDataSource) {
        this.setState({
          dataSource: depCopy(this.cloneDataSource),
          isAdd: false,
        });
      }
    }
    // if (nextProps.quotationType!=this.props.quotationType&&nextProps.quotationType == '4') {
    //   const { dataSource } = this.state
    //   this.setState({
    //     dataSource: [{
    //       ...dataSource[0],
    //       oldPledgeBondCode: this.state.oldPledgeBondCode,
    //       oldPledgeBondName: this.state.oldPledgeBondName,
    //       oldTransactionAmount: this.state.oldTransactionAmount
    //     }]
    //   })
    // }
  }

  //给父元素调用（指令下达），返回质押券信息
  getData = () => {
    return this.state.dataSource;
  };

  //给父元素调用 （切换委托方向 组合 取消 确定/指令方向），清空质押券信息
  clearData = () => {
    this.setState({
      dataSource: [],
    });
    this.cloneDataSource = null;
  };

  //给父元素调用 （点击持仓分析-质押券代码），模态框数据回填
  addNewPledgeBondData = () => {
    const { addNewPledgeBondData } = this.props;
    // const { select1 } = this.props
    // let data = select1.find((item) => item.pledgeBondCode == addNewPledgeBondData.pledgeBondCode)
    // this.setState({
    //   pledgeBondCode: addNewPledgeBondData.pledgeBondCode,
    //   // totalFaceValue:addNewPledgeBondData.remainingDenomination,
    //   pledgeBondName: addNewPledgeBondData.pledgeBondName,
    //   canUse: addNewPledgeBondData.canUse, //设置T+0可用（手）
    //   dueDate: addNewPledgeBondData.dueDate, //设置T+0可用（手）
    //   sybj: data.sybj,
    //   title: '新增',
    //   visible: true
    // })
    this.setState({ dataSource: [] }, () => {
      this.setState({
        dataSource: [
          {
            id: addNewPledgeBondData.id,
            pledgeBondCode: addNewPledgeBondData.pledgeBondCode,
            amount: addNewPledgeBondData.canUse, //设置T+0可用（手）
            isEdit: true,
          },
        ],
        pledgeBondName: addNewPledgeBondData.pledgeBondName,
        pledgeBondCode: addNewPledgeBondData.pledgeBondCode,
        canUse: addNewPledgeBondData.canUse, //设置T+0可用（手）
        dueDate: addNewPledgeBondData.dueDate,
        isAdd: true,
      });
    });
  };

  //给父元素调用 （点击在途回购信息-回购代码），表数据回填
  reNewPledgeBondData = () => {
    const { reNewPledgeBondData } = this.props;
    let newDataSource = _.cloneDeep(reNewPledgeBondData.pledgeVo);
    if (this.props.quotationType == '4') {
      newDataSource[0].isEdit = true;
      newDataSource[0].oldPledgeBondCode = newDataSource[0].pledgeBondCode;
      newDataSource[0].oldPledgeBondName = newDataSource[0].pledgeBondName;
      newDataSource[0].oldTransactionAmount = newDataSource[0].transactionAmount;
      newDataSource[0].amount = newDataSource[0].canUse;
      this.setState({ isAdd: true });
    }
    this.setState({
      dataSource: newDataSource,
      oldPledgeBondCode: newDataSource[0].pledgeBondCode,
      oldPledgeBondName: newDataSource[0].pledgeBondName,
      oldTransactionAmount: newDataSource[0].transactionAmount,
    });
    this.dataSource1 = _.cloneDeep(reNewPledgeBondData.pledgeVo);
  };

  //给父组件调用更新数据
  changeDataSource = (repoRate) => {
    const { occupationDays } = this.props;
    if (this.state.dataSource && this.state.dataSource.length > 0) {
      this.state.dataSource.map((item) => {
        // 回购利息=(成交金额*(回购利率/100)*实际占款天数)/365
        let repurchaseInterest = (((item.transactionAmount * Number(repoRate)) / 100) * Number(occupationDays)) / 365;
        item.repurchaseInterest = repurchaseInterest;
        // 到期结算金额=成交金额+回购利息
        item.expireAmount = Number(item.transactionAmount) + repurchaseInterest;
      });
    }
  };

  //给父组件调用更新数据,实际占款天数改变,更新质押券表的数据
  changeDataSource1 = (occupationDays) => {
    const { repoRate } = this.props;
    if (this.state.dataSource && this.state.dataSource.length > 0) {
      this.state.dataSource.map((item) => {
        // 回购利息=(成交金额*(回购利率/100)*实际占款天数)/365
        let repurchaseInterest = (((item.transactionAmount * Number(repoRate)) / 100) * Number(occupationDays)) / 365;
        item.repurchaseInterest = repurchaseInterest;
        // 到期结算金额=成交金额+回购利息
        item.expireAmount = Number(item.transactionAmount) + repurchaseInterest;
      });
    }
  };

  //融资质押券代码改变
  zyqdmOnChange = (e) => {
    const {
      select1,
      form: { setFieldsValue },
    } = this.props;
    let data = select1.find((item) => item.pledgeBondCode == e);
    //设置对应的质押券名称
    this.setState({
      pledgeBondName: data?.pledgeBondName,
      pledgeBondCode: data?.pledgeBondCode,
      canUse: data?.canUse, //设置T+0可用（手）
      dueDate: data?.dueDate,
      sybj: data?.sybj,
      //重置表格内容
      dataSource: [
        {
          id: this.state.dataSource[0].id,
          oldPledgeBondCode: this.state.oldPledgeBondCode,
          oldPledgeBondName: this.state.oldPledgeBondName,
          oldTransactionAmount: this.state.oldTransactionAmount,
          amount: data?.canUse,
          isEdit: true,
        },
      ],
    });
    setFieldsValue({
      pledgeAmount: '',
      conversionRate: '',
    });
  };

  //融券质押券代码改变
  securitiesCodeChange = (e) => {
    const {
      form: { setFieldsValue },
    } = this.props;
    //拿到一手多少钱
    // if (e && e.secucode) {
    //   this.setState({
    //     pledgeAmountDisabled: true
    //   }, () => {
    //     this.props.dispatch({
    //       type: 'exchangeAgreement/queryBondInfo',
    //       payload: {
    //         secucode: e.secucode,
    //       },
    //     }).then((res) => {
    //       if (res && res.success) {
    //         this.setState({
    //           sybj: res.data.sybj,
    //           pledgeBondName: res.data.secuabbr,
    //           pledgeAmountDisabled: false
    //         })
    //       }
    //     });
    //   })
    // }
    setFieldsValue({
      pledgeAmount: '',
      conversionRate: '',
    });
    this.setState({
      pledgeBondName: e?.secuabbr,
      pledgeBondCode: e?.tradingCode,
      //重置表格内容
      dataSource: [
        {
          id: this.state.dataSource[0].id,
          exchange: e?.exchangeCode,
          oldPledgeBondCode: this.state.oldPledgeBondCode,
          oldPledgeBondName: this.state.oldPledgeBondName,
          oldTransactionAmount: this.state.oldTransactionAmount,
          isEdit: true,
        },
      ],
    });
  };

  //原质押券代码改变
  yzyqdmOnChange = (e) => {
    const { select2 } = this.props;
    let data = select2.find((item) => item.pledgeBondCode == e);
    this.setState({
      oldPledgeBondName: data.pledgeBondShortName, //设置对应的原质押券名称
      oldTransactionAmount: data.expireAmount, //设置对应的原成交申报成交金额
    });
  };

  //质押券数量改变
  zyqssOnChange = (e) => {
    const {
      occupationDays,
      repoRate,
      form: { getFieldValue },
    } = this.props;
    const { dataSource } = this.state;
    //只有选择了质押券代码才进行计算操作
    if (getFieldValue('pledgeBondCode')) {
      if (e == 0) {
        dataSource[0].totalFaceValue = undefined;
        dataSource[0].transactionAmount = undefined;
        dataSource[0].repurchaseInterest = undefined;
        dataSource[0].expireAmount = undefined;
      } else {
        dataSource[0].totalFaceValue = 100 * e;
        if (getFieldValue('conversionRate')) {
          //成交金额=质押券数量*100*折算率/100
          let transactionAmount = (e * 100 * getFieldValue('conversionRate')) / 100;
          // 回购利息=(成交金额*(回购利率/100)*实际占款天数)/365
          let repurchaseInterest = (((transactionAmount * Number(repoRate)) / 100) * Number(occupationDays)) / 365;
          // 到期结算金额=成交金额+回购利息
          let expireAmount = transactionAmount + repurchaseInterest;
          dataSource[0].transactionAmount = transactionAmount;
          dataSource[0].repurchaseInterest = repurchaseInterest;
          dataSource[0].expireAmount = expireAmount;
        }
      }
      this.setState({ dataSource: dataSource });
    }
  };

  //折算比率改变
  zsblOnChange = (e) => {
    const {
      occupationDays,
      repoRate,
      form: { getFieldValue },
    } = this.props;
    const { dataSource } = this.state;
    // 券面总额有值并且折算比率大于0小于100  计算成交金额
    if (getFieldValue('pledgeAmount') && 0 < Number(e) && Number(e) <= 100) {
      //成交金额=质押券数量*100*折算率/100
      let transactionAmount = (getFieldValue('pledgeAmount') * 100 * e) / 100;
      // 回购利息=(成交金额*(回购利率/100)*实际占款天数)/365
      let repurchaseInterest = (((transactionAmount * Number(repoRate)) / 100) * Number(occupationDays)) / 365;
      // 到期结算金额=成交金额+回购利息
      let expireAmount = transactionAmount + repurchaseInterest;
      dataSource[0].transactionAmount = transactionAmount;
      dataSource[0].repurchaseInterest = repurchaseInterest;
      dataSource[0].expireAmount = expireAmount;
    }
    if (Number(e) == 0) {
      dataSource[0].transactionAmount = undefined;
      dataSource[0].repurchaseInterest = undefined;
      dataSource[0].expireAmount = undefined;
    }
    this.setState({ dataSource: dataSource });
  };

  //点击新增
  add = () => {
    if (this.state.dataSource.length > 0) {
      message.warning('只允许增加一条质押券信息');
      return;
    }
    this.setState({ dataSource: [{ id: uuid(32), isEdit: true }], isAdd: true });
  };

  //保存
  save = () => {
    const {
      form: { validateFields },
      orderSide,
      settlementDate,
      quotationType,
    } = this.props;
    const { dueDate, canUse, dataSource, pledgeBondCode, pledgeBondName } = this.state;
    validateFields((err, fieldsValue) => {
      if (!err) {
        if (fieldsValue.pledgeAmount == 0) {
          message.error('质押券数量需大于0');
          return;
        }
        if (orderSide == '2') {
          if (Number(fieldsValue.pledgeAmount) > Number(canUse)) {
            message.warning('融资回购时质押券数量不能大于T+0可用数量');
            return;
          }
          //判断日期
          if (settlementDate >= moment(dueDate).format('YYYYMMDD')) {
            message.warning('融资回购时当前质押券到期日要大于回购到期结算日');
            return;
          }
        }

        dataSource[0].pledgeBondCode = pledgeBondCode;
        dataSource[0].pledgeBondName = pledgeBondName;
        dataSource[0].pledgeAmount = fieldsValue.pledgeAmount;
        dataSource[0].conversionRate = fieldsValue.conversionRate;
        dataSource[0].isEdit = undefined;
        dataSource[0].dueDate = dueDate;
        this.setState({ dataSource: dataSource, isAdd: false });
        this.props.changeFee(1, dataSource[0].transactionAmount);
      }
    });
  };

  //点击取消
  cancel = () => {
    if (this.state.isAdd) {
      this.setState({ dataSource: [], isAdd: false });
      this.cloneDataSource = null;
      this.dataSource1 = null;
    } else {
      this.setState({ dataSource: [{ ...this.state.editDataSource[0], isEdit: undefined }], isAdd: false });
    }
  };

  //删除某条
  delete = (record, index) => {
    const { quotationType } = this.props;
    if (quotationType == null) {
      message.warning('请先选择报价类型');
      return;
    }
    if (quotationType != '1') {
      message.warning('此报价类型不支持删除');
      return;
    }

    this.setState({
      dataSource: [],
    });
    this.props.changeFee(0);
  };

  //编辑某条,数据回填  -----融券点编辑有问题，第一次回填ok，第二次回填就不能正常显示了
  edit = (record, index) => {
    const { quotationType } = this.props;
    const { dataSource } = this.state;
    this.setState({ editDataSource: _.cloneDeep(dataSource) });
    if (quotationType == null) {
      message.warning('请先选择报价类型');
      return;
    }
    if (quotationType == '2' || quotationType == '3' || quotationType == '5' || quotationType == '11') {
      message.warning('此报价类型不支持编辑');
      return;
    }
    if (quotationType == '4') {
      this.setState({
        dataSource: [
          {
            id: dataSource[0].id,
            isEdit: true,
            oldPledgeBondCode: dataSource[0].pledgeBondCode,
            oldPledgeBondName: dataSource[0].pledgeBondName,
            oldTransactionAmount: dataSource[0].transactionAmount,
          },
        ],
        // oldPledgeBondCode: dataSource[0].pledgeBondCode,
        // oldPledgeBondName: dataSource[0].pledgeBondName,
        // oldTransactionAmount: dataSource[0].transactionAmount
      });
    } else {
      // dataSource[0].oldPledgeBondCode = undefined
      // dataSource[0].oldPledgeBondName = undefined
      // dataSource[0].oldTransactionAmount = undefined
      this.setState({
        dataSource: [
          {
            ...dataSource[0],
            isEdit: true,
          },
        ],
        // oldPledgeBondCode: undefined,
        // oldPledgeBondName: undefined,
        // oldTransactionAmount: undefined
      });
    }

    // let data = select1.find((item) => item.pledgeBondCode == record.pledgeBondCode)
    // if (data) {
    //   this.setState({
    //     sybj: data.sybj,
    //   })

    // } else {
    //   //拿到一手多少钱
    //   this.props.dispatch({
    //     type: 'exchangeAgreement/queryBondInfo',
    //     payload: {
    //       tradingCode: record.pledgeBondCode,
    //       exchangeCode: '101'
    //     },
    //   }).then((res) => {
    //     if (res && res.success) {
    //       this.setState({
    //         sybj: res.data.sybj
    //       })
    //     }
    //   });
    // }
  };

  changeColumns = () => {
    const {
      form: { getFieldDecorator },
    } = this.props;
    let pledgeBondCodeWidths = 70; //质押券列宽
    let pledgeAmountWidths = 105; //质押券数量列宽
    let conversionRateWidths = 110; //折算比例列宽
    if (!this.state.dataSource[0]?.isEdit) {
      if (this.state.dataSource.length == 1) {
        pledgeBondCodeWidths = this.state.dataSource[0].pledgeBondCode?.length * 14 + this.state.dataSource[0].pledgeBondName?.length * 23;
      }
    } else {
      //新增或编辑状态需要改变列宽
      pledgeBondCodeWidths = 200;
      pledgeAmountWidths = 160;
      conversionRateWidths = 140;
    }

    const columns = [
      {
        title: '质押券',
        key: 'pledgeBondCode',
        width: pledgeBondCodeWidths,
        render: (val, record) => {
          if (record.isEdit) {
            if (this.props.orderSide == '2') {
              return (
                <FormItem>
                  {getFieldDecorator('pledgeBondCode', {
                    initialValue: this.props.quotationType == '4' ? null : val ? val : null,
                    rules: [{ required: true, message: '请选择质押券代码' }],
                  })(
                    <Select onChange={(e) => this.zyqdmOnChange(e)} disabled={this.state.disabled} style={{ width: 180 }}>
                      {this.props.select1?.map((item) => {
                        return <Select.Option key={item.pledgeBondCode}>{`${item.pledgeBondCode}-${item.pledgeBondName}`}</Select.Option>;
                      })}
                    </Select>,
                  )}
                </FormItem>
              );
            } else {
              return (
                <SecuritiesCodeC
                  disabled={this.state.disabled}
                  form={this.props.form}
                  initialValue={this.props.quotationType == '4' ? null : val ? record.exchange + '-' + val : null}
                  queryItems={{ exchangeCode: '101' }}
                  titleDisplay={false}
                  dataIndex='pledgeBondCode'
                  codeType={codeType.zq}
                  rules={[{ required: true, message: '请选择质押券代码' }]}
                  onChange={(e) => this.securitiesCodeChange(e)}
                  positionBody={true}
                />
              );
            }
          } else {
            return val + '-' + record.pledgeBondName;
          }
        },
      },
      {
        title: '质押券数量',
        key: 'pledgeAmount',
        type: 'number',
        width: pledgeAmountWidths,
        render: (val, record) => {
          if (record.isEdit) {
            return (
              <InputNumberC
                form={this.props.form} // form对象
                dataIndex={'pledgeAmount'}
                unit='张'
                min={0}
                precision={0}
                initialValue={this.props.quotationType == '4' ? null : val ? val : null}
                splitStyle={true}
                onChange={(e) => this.zyqssOnChange(e)}
                rules={[{ required: true, message: '请输入质押券数量' }]}
              />
            );
          } else {
            return val;
          }
        },
      },
      {
        title: '折算比例(%)',
        key: 'conversionRate',
        width: conversionRateWidths,
        render: (val, record) => {
          if (record.isEdit) {
            return (
              <InputNumberC
                form={this.props.form} // form对象
                dataIndex={'conversionRate'}
                unit='%'
                min={0}
                max={100}
                precision={2}
                initialValue={this.props.quotationType == '4' ? null : val ? val : null}
                onChange={(e) => this.zsblOnChange(e)}
                rules={[{ required: true, message: '请输入折算比率' }]}
              />
            );
          } else {
            return Number(val).toFixed(2);
          }
        },
      },
      //交易方向为“融资回购”时，展示该列
      ...(this.props.orderSide == '2' ? [{ title: '可用数量', key: 'amount', type: 'number', width: '105px' }] : []),
      { title: '质押券券面总额(元)', key: 'totalFaceValue', type: 'money', width: '190px' },
      { title: '成交金额(元)', key: 'transactionAmount', type: 'money', width: '180px' },
      { title: '回购利息(元)', key: 'repurchaseInterest', type: 'money', width: '120px' },
      { title: '到期结算金额(元)', key: 'expireAmount', type: 'money', width: '160px' },
      ...(this.props.quotationType == '4'
        ? [
            {
              //报价类型为换券申报时，展示该列
              title: '原质押券',
              key: 'oldPledgeBondCode',
              width: 200,
              render: (val, record) => {
                if (val) {
                  return record.oldPledgeBondCode + '-' + record.oldPledgeBondName;
                } else {
                  return '--';
                }
              },
            },
          ]
        : []),
      //报价类型为换券申报时，展示该列
      ...(this.props.quotationType == '4' ? [{ title: '原成交申报成交金额(元)', key: 'oldTransactionAmount', type: 'money', width: '240px' }] : []),
      ...(this.props.type < 3 || this.props.type == 11
        ? [
            {
              title: '操作',
              dataIndex: 'operate',
              key: 'operate',
              type: 'operate',
              fixed: 'right',
              width: 110,
              operates: [
                {
                  title: '编辑',
                  onClick: (record, index) => this.edit(record, index),
                  rules: { hide: { items: [{ key: 'isEdit', value: [undefined], relation: ['!='] }] } },
                },
                {
                  title: '删除',
                  onClick: (record, index) => this.delete(record, index),
                  rules: { hide: { items: [{ key: 'isEdit', value: [undefined], relation: ['!='] }] } },
                },
                {
                  title: '保存',
                  onClick: (record, index) => this.save(record, index),
                  rules: { hide: { items: [{ key: 'isEdit', value: [undefined], relation: ['='] }] } },
                },
                {
                  title: '取消',
                  onClick: (record, index) => this.cancel(record, index),
                  rules: { hide: { items: [{ key: 'isEdit', value: [undefined], relation: ['='] }] } },
                },
              ],
            },
          ]
        : []),
    ];
    return columns;
  };

  // zyqinfo = () => {
  //   const { getFieldDecorator } = this.props.form;
  //   const { select1, select2, quotationType, settlementDate, repoRate, orderSide } = this.props
  //   let newSelect2 = []
  //   if (select2 && select2.length && select2.length > 0) {
  //     newSelect2 = this.arrayUnique(select2, 'pledgeBondCode')
  //   }
  //   if (quotationType && settlementDate && repoRate) {
  //     this.setState({
  //       addDisable: false
  //     })
  //   } else {
  //     this.setState({
  //       addDisable: true
  //     })
  //   }

  //   if (quotationType == '4' || quotationType == '9') {
  //     this.setState({
  //       oldPledgeBondCodeDisable: true
  //     })
  //   } else {
  //     this.setState({
  //       oldPledgeBondCodeDisable: false
  //     })
  //   }
  //   return (
  //     <div >
  //       <Form className={style.formStyle} >
  //         <Row>
  //           {(orderSide == '融资回购' || orderSide == '2') ? <Col span={12}>
  //             <FormItem label="质押券代码"   {...formItemLayout}>
  //               {getFieldDecorator('pledgeBondCode', {
  //                 initialValue: this.state.pledgeBondCode ? this.state.pledgeBondCode : null,
  //                 rules: [{ required: true, message: '请选择质押券代码' }],
  //               })(<Select onChange={e => this.zyqdmOnChange(e)} disabled={this.state.disabled}>
  //                 {select1 && select1.length ? select1.map((item) => {
  //                   return (<Select.Option key={item.pledgeBondCode}>{`${item.pledgeBondCode}-${item.pledgeBondName}`}</Select.Option>)
  //                 }) : null}
  //               </Select>)}
  //             </FormItem>
  //           </Col> : <Col span={12}>
  //             <SecuritiesCodeC
  //               disabled={this.state.disabled}
  //               initialValue={this.state.pledgeBondCode ? this.state.pledgeBondCode : null}
  //               form={this.props.form}
  //               queryItems={this.state.queryItems}
  //               dataIndex='pledgeBondCode'
  //               codeType={codeType.zq}
  //               extraLayout={formItemLayout}
  //               rules={[{ required: true, message: '请选择质押券代码' }]}
  //               title='质押券代码'
  //               onChange={e => this.securitiesCodeChange(e)}
  //             />
  //           </Col>}

  //           <Col span={12}>
  //             <FormItem label="原质押券代码"   {...formItemLayout}>
  //               {getFieldDecorator('oldPledgeBondCode', {
  //                 initialValue: this.state.oldPledgeBondCode ? this.state.oldPledgeBondCode : null,
  //                 rules: [{ message: '请选择原质押券代码' }],
  //               })(<Input disabled />)
  //               }

  //             </FormItem>
  //           </Col>

  //           <Col span={12} style={{ marginTop: '1px' }}>
  //             <FormItem label="质押券数量"   {...formItemLayout}>
  //               {getFieldDecorator('pledgeAmount', {
  //                 initialValue: this.state.pledgeAmount ? this.state.pledgeAmount : null,
  //                 rules: [{ required: true, message: '请输入质押券数量' },
  //                 { pattern: /^\+?[1-9]\d*$/, message: '质押券数量必须为正整数' }],
  //                 validateTrigger: 'onBlur',
  //               })(<Input disabled={this.state.pledgeAmountDisabled} onChange={e => this.zyqssOnChange(e)} />)}
  //             </FormItem>
  //           </Col>
  //           <Col span={12} style={{ marginTop: '1px' }}>
  //             <FormItem label="折算比率(%)"   {...formItemLayout}>
  //               {getFieldDecorator('conversionRate', {
  //                 initialValue: this.state.conversionRate ? this.state.conversionRate : null,
  //                 rules: [{ required: true, message: '请输入折算比率' },
  //                 { pattern: /^100.00$|^0\.0*[1-9]\d*$|^[1-9](\.\d+)?$|^[1-9]\d(\.\d+)?$/, message: '折算比率必须大于0小于等于100' }
  //                 ],
  //                 validateTrigger: 'onBlur',
  //               })(<InputNumber precision={2} onChange={e => this.zsblOnChange(e)} />)}
  //             </FormItem>
  //           </Col>
  //           <Col span={12} style={{ marginTop: '1px' }}>
  //             <FormItem label="质押券面总额(元)"   {...formItemLayout}>
  //               {getFieldDecorator('totalFaceValue', {
  //                 initialValue: this.state.totalFaceValue ? this.state.totalFaceValue : null,
  //                 rules: [{ required: true, message: '请输入质押券面总额' }],
  //               })(<Input disabled />)}
  //             </FormItem>
  //           </Col>
  //           <Col span={12} style={{ marginTop: '1px' }}>
  //             <FormItem label="成交金额(元)"   {...formItemLayout}>
  //               {getFieldDecorator('transactionAmount', {
  //                 initialValue: this.state.transactionAmount ? this.state.transactionAmount : null,
  //                 rules: [{ required: true, message: '请输入成交金额' }],
  //               })(<Input disabled formatter={inValue => fixedNum(inValue, 2)} />)}
  //             </FormItem>
  //           </Col>
  //           <Col span={12} style={{ marginTop: '1px' }}>
  //             <FormItem label="回购利息(元)"   {...formItemLayout}>
  //               {getFieldDecorator('repurchaseInterest', {
  //                 initialValue: this.state.repurchaseInterest,
  //                 rules: [
  //                   { pattern: /^(?!(0[0-9]{0,}$))[0-9]{1,}[.]{0,}[0-9]{0,}$/, message: '回购利息必须大于等于0' }],
  //                 validateTrigger: 'onBlur',
  //               })(<InputNumber disabled precision={2} />)}
  //             </FormItem>
  //           </Col>
  //           <Col span={12} style={{ marginTop: '1px' }}>
  //             <FormItem label="到期结算金额(元)"   {...formItemLayout}>
  //               {getFieldDecorator('expireAmount', {
  //                 initialValue: this.state.expireAmount ? this.state.expireAmount : null,
  //                 rules: [
  //                   { pattern: /^(?!(0[0-9]{0,}$))[0-9]{1,}[.]{0,}[0-9]{0,}$/, message: '到期结算金额必须大于等于0' }],
  //                 validateTrigger: 'onBlur',
  //               })(<InputNumber disabled precision={2} suffix="元" />)}
  //             </FormItem>
  //           </Col>

  //         </Row>
  //       </Form>
  //     </div>)
  // }

  render() {
    const { quotationType, settlementDate, repoRate, type } = this.props;
    const newColumns = this.changeColumns();
    if (settlementDate && repoRate) {
      this.setState({ addDisable: false });
    } else {
      this.setState({ addDisable: true });
    }
    return (
      <div style={{ position: 'relative' }}>
        {this.state.hide == false && <PrimaryC title='新增' onClick={() => this.add()} />}
        <div className={style.bgcolor} style={{ marginTop: '10px' }}>
          <TableC columns={newColumns} dataSource={this.state.dataSource} hidePage={true} scroll={{ x: 1400, y: 350 }} />
        </div>
        {this.state.addDisable && (type == '1' || type == '2' || type == 10 || type == 11) && (
          <div>
            <NoDataMaskC height={'100%'} title='请选择回购利率,到期结算日，加载数据！' />
          </div>
        )}
      </div>
    );
  }
}
